package com.example.badyloans.controller;

import com.example.badyloans.common.ReturnResult;
import com.example.badyloans.config.CalculationLiXIJIS;
import com.example.badyloans.pojo.*;
import com.example.badyloans.servlet.*;
import com.example.badyloans.util.PageSupport;
import com.sun.xml.internal.bind.v2.TODO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Primary;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

/**
 * @author 啊桥哦
 * @Description:
 * @date 2020-07-14 11:54
 */
@Api("用户信息相关控制器")
@RestController
public class UserinfoController {
    @Resource
    private TUserInfoService tUserInfoService;
    @Resource
    private TBidService tBidService;
    @Resource
    private TUserWalletService tUserWalletMapper;
    @Resource
    private TBorrowService tBorrowService;
    @Resource
    private TRepaymentDetailService tRepaymentDetailService;

    /**
     * 查询个人资料
     * @param accountId
     * @return
     */
    @ApiOperation("查询个人资料")
    @RequestMapping("user/userinfo/get/{accountId}")
    public ReturnResult userinfogetaccountId(@PathVariable String  accountId){
        TUserInfo tUserInfo = new TUserInfo();
        if (StringUtils.isEmpty(accountId)) {
           return  ReturnResult.fail("参数不能为空");
        }
        tUserInfo = tUserInfoService.selectByPrimaryKey(accountId);
        if(tUserInfo==null){
            tUserInfo=new TUserInfo();
            tUserInfo.setAvatar("/avatar/nobody.JPG/");
        }
        return ReturnResult.success(tUserInfo,null);
    }

    /**
     * 投标方法
     * @return
     */
    @PostMapping("finance/bid/add")
    public ReturnResult bidadd(TBid bid){
        ReturnResult returnResult=tBidService.addBid(bid);
        return  returnResult;
    }

    /**
     * 后台满标审核
     * @return
     */
    @PostMapping("finance/loan/audit")
    public Boolean loanaudit(TBid bid){
        Boolean aBoolean=tBidService.selecttwo(bid);
        return  aBoolean;
    }

    @PostMapping("finance/repayment/detail/query")
    public ReturnResult repaymentdetailquery(@RequestParam String userId, loginlog loginlog){
        if (StringUtils.isEmpty(userId)) {
            return  ReturnResult.fail("参数为空");
        }
        PageSupport page=new PageSupport();
        page.setPageSize(4);
        page.setTotalCount(tRepaymentDetailService.count(userId)); //查询总记录数
        page.setCurrentPageNo(loginlog.getCurrentPage());
        Integer pageSize=page.getPageSize();       //拿到页大小
        Integer currentPageNo=page.getCurrentPageNo(); //拿到页码
        List<TRepaymentDetail> tRepaymentDetails=null;
        tRepaymentDetails=tRepaymentDetailService.selectByPrimaryKey1(userId,((currentPageNo-1)*pageSize),pageSize);
        return ReturnResult.success(tRepaymentDetails,page);
    }
}
